Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ refactoring searchable-params test to use test.each #2

Conversation

augustodia
Copy link
Contributor

@augustodia augustodia commented Jan 16, 2024

In this pull request, the unit tests for the SearchParams class have been significantly refactored. The main change is the use of Jest's test.each function, which allows us to run the same test multiple times with different inputs. This makes the tests more concise and easier to maintain, as we can add, remove, or modify test cases simply by modifying an array of parameters.

Additionally, the test labels (the descriptions that appear when the tests are run) have been parameterized. This means that the specific values being tested are included in the test label, making it easier to understand what each test is doing and identify which test has failed if there are any failures.

Here's an example of what the new tests look like:

test.each([
  { page: null, expected: 1 },
  { page: undefined, expected: 1 },
  { page: '', expected: 1 },
  // ... other test cases
])('page prop %p', ({ page, expected }) => {
  const params = new SearchParams();
  expect(params.page).toBe(1);
  // ... rest of the test
});

In this example, %p in the test label is replaced with the value of entry for each test case. This makes it clear what value is being tested in each run of the test.

@argentinaluiz argentinaluiz merged commit d7bad89 into devfullcycle:main Jan 23, 2024
1 of 2 checks passed
@argentinaluiz
Copy link
Contributor

Opa Luiz @augustodia !

Muito obrigado pela sua contribuição, está aprovado!

@augustodia augustodia deleted the refactor/implements-test-each-in-search-params branch April 5, 2024 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants